package org.bbl.db.mybatis.mysql;

import java.util.Map;

/**
 * @author biniamg
 * @since 10/31/12
 */
public class DynamicSqlSelectProvider {

    public String doWriteQuery(Map<String, Object> params) {
        return (String) params.get("query");
    }

    public String doReadQuery(Map<String, Object> params) {
        String query = (String) params.get("param1");
        return replaceRec(query, 2, params.size());
    }

    private String replaceRec(String query, int i, int max) {
        if (i >= max) {
            return query.replaceFirst("\\?", " #{param" + i + "} ");
        }
        return replaceRec(query.replaceFirst("\\?", " #{param" + i + "} "), ++i, max);
    }
}
